﻿@model VietPremier.Areas.AdminCP.Models.TravelHotelModel
@{
    ViewBag.Title = "Khách sạn du lịch";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}
@helper Truncate(string input, int length)
{
    if (input.Length <= length)
    { 
        @Html.Raw(input)
    }
    else
    { 
        @Html.Raw(input.Substring(0, length))<text>...</text>
    }
}

<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        check();
    });

    //bắt sự kiện của checkbox 
    $(".Promotion").live("click", function () {
        var recordID = $(this).attr("data-id");
        var getURL = '@Url.Action("SetPromotion", "AdminTravelHotel")';
        $.post(getURL, { "id": recordID }, function (data) { alert("Thay đổi thành công") });
    });

    function check() {        
        $('#SubmitID').hide();
        $('#idTravelCity').change(function () {
            var checkValue = $("#idTravelCity").val();
            if (checkValue > 0) {
                $('#SubmitID').show();
            } else {
                $('#SubmitID').hide();
            }
        });
    }
    
    function DeleteRecord(id, id_TravelProduct, id_TravelCity) {
        var answer = confirm("Are you sure to delete this record?");
        if (answer) {
            var getURL = '@Url.Action("Delete", "AdminTravelHotel")';
            $.get(getURL, { "id": id }, function (data) {
                if (data == "Ok") {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");                    
                    var strTemp = '@Url.Action("Index", "AdminTravelHotel", new { idTravelProduct = "id_TravelProduct", idTravelCity = "id_TravelCity"})';
                    strTemp = strTemp.replace("id_TravelProduct", id_TravelProduct).replace("id_TravelCity", id_TravelCity);
                    // cắt string hef lúc đầu vì nó có thêm ký tự 'amp;'
                    var strline = strTemp.split('amp;');
                    var strhef = strline[0] + strline[1];
                    window.location.href = strhef;
                }
                else {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                    alertMsg("Cannot delete, Please contact to website's technical");
                    //window.location.href = '@Url.Action("Index", "Error", new { errorMsg = "Can not delete!" })';
                }
            });
        }
        else {
            return false;
        }

        return false;
    }

</script>


<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminTravelProduct")">Quản lý sản phẩm du lịch</a></li>
        @if (@Model.listCategoryId.IdTravelCity > 0 )
        {
           <li class="current"><a href="@Url.Action("Insert", "AdminTravelHotel", new { idTravelCity = Model.listCategoryId.IdTravelCity, idTravelProduct = Model.listCategoryId.IdTravelProduct })" >Thêm khách sạn du lịch mới</a></li>
        }
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->


    <div class="contenttitle radiusbottom0">
        <h2 class="table"><span>Chọn tour du lịch mà bạn muốn</span></h2>
    </div>
    <!--contenttitle-->


    @using (Html.BeginForm("Index", "AdminTravelHotel", FormMethod.Post, new { @class = "tableoptions", style = "padding-left:10px" }))
    {
        @Html.DropDownList("idTravelCity", Model.category as SelectList, "--Select a City--", new { id = "idTravelCity", @class = "radius3" })
                   
        <button id="SubmitID" class="radius3">Submit</button>
        
    }

    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
        <colgroup>
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con0" />
            <col class="con1" />
        </colgroup>
        <thead>
            <tr>
                <th class="head1"></th>
                <th class="head0">Ảnh</th>
                <th class="head1">Tên</th>
                <th class="head0">Địa chỉ</th>
                <th class="head1">Điện thoại</th>
                <th class="head0">Đánh giá(*)</th>
                @*<th class="head1">Promotion</th>*@
                <th class="head1">Thao tác</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th class="head1"></th>
                <th class="head0">Ảnh</th>
                <th class="head1">Tên</th>
                <th class="head0">Địa chỉ</th>
                <th class="head1">Điện thoại</th>
                <th class="head0">Đánh giá(*)</th>
                @*<th class="head1">Promotion</th>*@
                <th class="head1">Thao tác</th>
            </tr>
        </tfoot>
        <tbody>
            @{
                if (Model.listTravelHotel != null)
                {
                    int i = 1;
                    foreach (var item in Model.listTravelHotel)
                    { 
                        <tr class="gradeX">
                             <td class="center">@i</td>
                            @{
                                var imageFile = "~/Content/upload/travelhotels/";
                                if (item.Image != null)
                                {
                                    imageFile += @item.Image;
                                }
                                else
                                {
                                    imageFile += "no-photo.jpg";
                                }
                            }
                            <td class="center">
                                <img src= "@Url.Content(imageFile)" style="width:50px; height:50px" alt="" />
                            </td>
                            <td>@Html.DisplayFor(modelitem => item.Name)</td>
                            <td>@Html.DisplayFor(modelitem => item.Address)</td>
                            <td class="center">@Html.DisplayFor(modelitem => item.Phone)</td>
                            <td class="center">@Html.DisplayFor(modelitem => item.Rate)</td>
                            @*<td class="center">
                               <input data-id="@item.Id" class="Promotion" type="checkbox" style="width:15px;" @(item.Promotion == true ? "checked= checked" : "") value="true"/>                       
                            </td> *@ 
                            @{
                                VietPremier.EntityAdmin user = (VietPremier.EntityAdmin)Session["User"];
                                if (user.Type == "Admin" || user.Type == "Manager")
                                {
                                    <td class="center">
                                       @* @Html.ActionLink("Thêm", "Insert", new { idTravelCity = item.IdTravelCity, idTravelProduct = Model.listCategoryId.IdTravelProduct })
                                        &nbsp;*@
                                        @Html.ActionLink("Sửa", "Edit", new { idTravelHotel = @item.Id, idTravelCity = @Model.listCategoryId.IdTravelCity, idTravelProduct = Model.listCategoryId.IdTravelProduct })
                                        &nbsp;
                                        <a href="#" onclick="DeleteRecord(@item.Id, @Model.listCategoryId.IdTravelProduct, @Model.listCategoryId.IdTravelCity)">Xóa</a> 
                                    </td>
                                }
                                else
                                {
                                    <td class="center">
                                       @* @Html.ActionLink("Thêm", "Insert", new { idTravelCity = item.IdTravelCity, idTravelProduct = Model.listCategoryId.IdTravelProduct })
                                        &nbsp;*@
                                        @Html.ActionLink("Sửa", "Edit", new { idTravelHotel = @item.Id, idTravelCity = @Model.listCategoryId.IdTravelCity, idTravelProduct = Model.listCategoryId.IdTravelProduct })                                        
                                    </td>
                                }
                            }                            
                        </tr>
                        i++;
                    }
                }
            }
        </tbody>
    </table>
</div>
<!--maincontentinner-->